package com.zzw.filters.httpfilters;

import com.zzw.annotation.runners.RequestResourceRunner;
import com.zzw.ratelimter.RedisRateLimiter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 */
@Configuration
public class HttpFilterConfiguration {

    public DefaultHttpFilter defaultHttpFilter() {
        return new DefaultHttpFilter();
    }

    @Bean
    @ConditionalOnProperty(prefix = "zzw.request.context.filter", name = "enable")
    public DefaultRequestContextFilter defaultRequestContextFilter() {
        return new DefaultRequestContextFilter();
    }

    @Bean
    @ConditionalOnBean(RedisRateLimiter.class)
    public DefaultRequestResourceContextFilter defaultRequestResourceContextFilter(RequestResourceRunner requestResourceRunner, RedisRateLimiter redisRateLimiter) {
        return new DefaultRequestResourceContextFilter(requestResourceRunner, redisRateLimiter);
    }
}
